#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>


typedef struct list
{
    int val;
    struct list* next;
}LT;

void SLTErase(LT** pphead, LT* pos)
{
    LT* prev = *pphead;
    while (prev->next != pos)
    {
        prev = prev->next;
    }
    prev->next = pos->next;

}

int main()
{
    int m, n;

    scanf("%d%d", &n, &m);
    LT* head = (LT*)malloc(sizeof(LT));
    LT* tail = head;

    LT* newnode;
    for (int i = 1; i <= n; i++)
    {
        newnode = (LT*)malloc(sizeof(LT));

        tail->val = i;
        tail->next = newnode;
        tail = tail->next;
    }
    tail->next = head->next;
    LT* prev = head->next;
    int j = m-1;
    while (head->next != head)
    {
        while (j--)
        {
            prev = prev->next;
        }
        LT* next = prev->next;

        SLTErase(&head, prev);
        j = m-1;
        prev = next;
    }
    printf("%d", head->val);

    return 0;
}